﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/QuizAdmin.Master" AutoEventWireup="true" CodeBehind="ViewAttempts.aspx.cs" Inherits="BladeTecWebApplication.Admin.ViewAttempts" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<script type="text/javascript">

	$(function () {
		
		$('#errorDialog').dialog({
			autoOpen: false,
			width: 400,
			modal: true,
			buttons: {
				"Ok": function () {
					$(this).dialog("close");
				}
			}
		});

		$('#errorSameQuiz').dialog({
			autoOpen: false,
			width: 400,
			modal: true,
			buttons: {
				"Ok": function () {
					$(this).dialog("close");
				}
			}
		});

	});

	function confirmDelete(confirmed) {

		if (!confirmed) {
			$("#dialog-confirm").dialog({
				resizable: false,
				height: 200,
				width: 400,
				modal: true,
				buttons: {
					"Delete Attempt": function () {
						$(this).dialog("close");
						$("#MainContent_deleteButtonHidden").click();
					},
					Cancel: function () {
						$(this).dialog("close");
					}
				}
			});
			return false;
		} else {
			return true;
		}

	}

	function validateSelected() {
		try {
			var hasSelected = $("input[type='checkbox']").is(':checked');
			if (hasSelected) {
				///
				var checkboxes = $("input[type='checkbox'][quiz_id]");
				var q_id = -1;
				for (var i = 0; i < checkboxes.length; i++) {
					if ($(checkboxes[i]).attr('checked')) {
						if (q_id == -1) {
							q_id = $(checkboxes[i]).attr('quiz_id');
							continue;
						}

						if ($(checkboxes[i]).attr('quiz_id') != q_id) {
							$('#errorSameQuiz').dialog('open');
							return false;
						}
					}
				}

				///

				return true;
			}
			else {
				$('#errorDialog').dialog('open');
				return false;
			}
		} catch (e) {
			return true;
		}
	}

</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<asp:Panel runat="server" ID="pnlViewQuizzes">
<span class="pageTitle">View Attempts</span>
<br /><br />

	<asp:panel runat="server" ID="pnlGrid">
		<asp:GridView ID="gvAttempts" runat="server" AutoGenerateColumns="false" CssClass="netsysTable"
			AlternatingRowStyle-CssClass="netsysTableRowAlt" 
			RowStyle-CssClass="netsysTableRow" BorderStyle="None" BorderWidth="0" 
			Width="100%">
			<Columns>
				<asp:TemplateField>
					<ItemTemplate>
						<input type="checkbox" quiz_id="<%#Eval("QUIZ_ID") %>" name="attempt_<%#Eval("ATTEMPT_ID") %>" value="<%#Eval("ATTEMPT_ID") %>" />
					</ItemTemplate>
				</asp:TemplateField>
				<asp:BoundField HeaderText="Applicant Name" DataField="FULL_NAME" />
				<asp:BoundField HeaderText="Attempt Date" DataField="ATTEMPT_DATE" DataFormatString="{0:d}" />
				<asp:TemplateField HeaderText="Score">
					<ItemTemplate>
						<%#Eval("CORRECT").ToString() + '/' + ((int)Eval("CORRECT")+(int)Eval("INCORRECT")).ToString() %>
						(<%#getPercentage((Double.Parse(Eval("CORRECT").ToString())), Double.Parse(Eval("INCORRECT").ToString()))+"%"%>)
					</ItemTemplate>
				</asp:TemplateField>
				<asp:TemplateField HeaderText="Graded">
					<ItemTemplate>
						<%# ((int)Eval("GRADED")==1)? "Yes":"No" %>
					</ItemTemplate>
				</asp:TemplateField>
				<asp:TemplateField HeaderText="">
					<ItemTemplate>
						<a href="EditAttempt.aspx?attempt_id=<%#Eval("ATTEMPT_ID") %>">Edit</a>
					</ItemTemplate>
				</asp:TemplateField>
				<asp:TemplateField HeaderText="">
					<ItemTemplate>
						<a target="_blank" href="PrintAttempt.aspx?attempt_id=<%#Eval("ATTEMPT_ID") %>">Print</a>
					</ItemTemplate>
				</asp:TemplateField>
			</Columns>
		</asp:GridView>

		<div style="width:100%; margin-top: 10px;">
			<asp:Button ID="btnDelete" runat="server" Text="Delete Selected" 
				onclick="btnDelete_Click" OnClientClick="return confirmDelete(false);" 
				ClientIDMode="Predictable" />
			<asp:Button ID="btnCompareApplicants" runat="server" Text="Compare Applicants" 
				onclick="btnCompareApplicants_Click" OnClientClick="return validateSelected();" />
			<div style="display:none">
				<asp:Button runat="server" OnClick="btnDelete_Click" ID="deleteButtonHidden" ClientIDMode="Predictable"/>
			</div>
		</div>
	</asp:panel>

	<asp:Panel ID="pnlNoAttempts" runat="server">
		There are no quiz attempts.
	</asp:Panel>

	<div id="dialog-confirm" title="Confirm Delete" style="display:none;">
		<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Are you sure you want to delete the selected applicant attempts? All quiz attempt data for the selected attempts will be lost.</p>
	</div>

</asp:Panel>

<div id="errorDialog" title="No Selection">
	Please select at least one applicant for comparison.
</div>

<div id="errorSameQuiz" title="Non-matching Quizzes">
	You have selected multiple applicants that have not taken the same quiz. Please only
	select applicants that have taken the same quiz.
</div>

</asp:Content>
